package com.nondo.rdp.finance.endpoint.api.app.advert;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.rdp.core.model.View;
import com.nondo.rdp.finance.domain.setting.advert.Advert;
import com.nondo.rdp.finance.service.setting.advert.AdvertService;

@RestController("apiAppAdvert")
@RequestMapping("/api/app/advert")
public class AdvertEndpoint {
    @Autowired
    AdvertService advertService;
    
    /**
     * 查看广告
     * @param request
     * @param response
     * @param id
     * @return
     */
    @RequestMapping("/info/{id}")
	public View<Advert> info(HttpServletRequest request, HttpServletResponse response,
			@PathVariable("id") Long id) {
		View<Advert> view = new View<Advert>(20000, "获取数据成功");
		
		Advert advert = null;
		if (id != null) {
			advert = advertService.findOne(id);
		} else {
			advert = new Advert();
		}

		view.setData(advert);
		return view;
	}
    
    /**
     * 获取广告列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @RequestMapping("/list/{type}")
    public View<List<Advert> > list(HttpServletRequest request, HttpServletResponse response, @PathVariable("type") Integer type) {
        View<List<Advert> > view = new View<List<Advert> >(20000, "获取列表成功");

        List<Advert> advertList = advertService.findAll(type);
        if (advertList == null) {
        	advertList = new ArrayList<Advert>();
        }
        view.setData(advertList);

        return view;
    }

}